home *** CD-ROM | disk | FTP | other *** search
- <html>
- <head>
- <title>Class ClientIO - Evans Java Toolkit</title>
- <meta name="description" content="Evans Programming Java Toolkit - ClientIO">
- <meta name="keywords" content="IO, java, read, write, server, client>
- <meta name="DESIGN" content="Evans Programming, Hoffman Estates, IL">
- </head>
-
- <body bgcolor="#FFFFFF" link="#FF0000" vlink="#800000" alink="#FF00FF">
-
- <!--INCLUDESTART="JTCLSHDR.TXT"-->
- <center>
- <font face="Arial" size="5" color="0000FF">
- <strong>Evans Programming Java Toolkit</strong><br>
- </font>
- </center>
-
- <center>
- <font size="-2" face="Arial" color="FF0000">
- <strong>
- <a href="../jtkit.htm", target="_top">Java Toolkit Page</a> |
- <a href="../softwr.htm", target="_top">Software</a> |
- <a href="../index.html", target="_top">Home</a><br>
- </strong>
- </font>
- </center>
- <!--INCLUDESTOP="JTCLSHDR.TXT"-->
- <!--INCLUDESTART="JTPGIDX.TXT"-->
- <center>
- <font size="-2" face="Arial" color="FF0000">
- <strong>
- <a href="#DESCRIPTION">Description</a> |
- <a href="#EXAMPLES">Examples</a> |
- <a href="#CONSTRUCTORS">Constructors</a> |
- <a href="#METHODS">Methods</a>
- </strong>
- </font>
- </center>
- <!--INCLUDESTOP="JTPGIDX.TXT"-->
- <!--INCLUDESTART="JTPGNAV.TXT"-->
-
-
- <a href="formtool.htm">Previous</a>
- <a href="serverio.htm">Next</a>
- <a href="classidx.htm">Index</a><br>
-
- <!--INCLUDESTOP="JTPGNAV.TXT"-->
-
- <hr>
- <h1>Class ClientIO</h1>
-
- <pre>
- public class evans.toolkit.<strong>ClientIO</strong>
- {
- // Constructors
- public <strong>ClientIO</strong>();
-
- // Methods
- public String <strong>talk</strong>(URL serversideEXE, String data);
- public boolean <strong>getLastResult</strong>();
- } </pre>
-
- <hr>
- <a name="DESCRIPTION"><img src="descript.gif" width=220 height=60 alt="Description"></a>
- <p>
- The primary function of ClientIO is to write to a web server file from a java applet.
- ClientIO can also receive data in the form of a response.
- A method is provided to test the results of the most recent write
- attempt.
- </p>
-
- <p>
- <strong>NOTE:</strong> A server side executable, named <a href="serverio.htm">serverio.exe</a>, is provided with the Evans Java Toolkit.
- It, or another CGI program, is required to accomplish java to web server i/o. The ClientIO class is
- the client side piece.
- </p>
-
- <hr>
- <a name="EXAMPLES"><img src="example.gif" width=220 height=60 alt="Examples"></a>
- <h3>Write To A Web Server</h3>
-
- <pre>
- // Write psvText and return a boolean indicating success or failure
- import java.net.*;
- import java.applet.*;
- import evans.toolkit.*;
-
- public class io extends Applet
- {
- public void init()
- {
- boolean bResult = false;
- bResult = clientIOexample("This is web server write example" + "\n");
- }
-
- // Write psvText and return a boolean indicating success or failure
- private boolean clientIOexample(String psvText)
- {
- URL url = null;
-
- // Construct a ClientIO object, oClientIO
- ClientIO oClientIO = new ClientIO();
-
- // Initialize reply variable
- String svAnswer = "";
-
- // We will write to the serverio.exe which will "post" the data
- // to the file specified in the serverio.ini file (located in
- // the cgi-bin directory).
- try
- {
- url = new URL("http://www.evans-programming.com/cgi-bin/serverio.exe");
- }
- catch (MalformedURLException me)
- {
- }
-
- // Write the data and get back a response
- svAnswer = oClientIO.talk(url, psvText);
-
- // Return boolean result. Note: svAnswer is not returned in this example
- return oClientIO.getLastResult();
- }
- }</pre>
-
- <dl>
- <dt><h3>Read From A Web Server</h3>
- <dd><p><strong>Note:</strong> Reading from a web server file is NOT part of the
- ClientIO class. The example provided here is for educational value only.</p>
- </dl>
-
- <pre>
- // Read and return data from a file on a web server
- // urlFile is a URL specifying the full file pathname of the file to read
- private String readFromFile(URL urlFile);
- {
- try
- {
- String svAns = "";
- String svIncoming = "";
-
- URLConnection connection = urlFile.openConnection();
-
- connection.setDoInput(true);
- connection.setDoOutput(false);
- connection.setAllowUserInteraction(false);
-
- DataInputStream inStream = new DataInputStream(connection.getInputStream());
- while ((svIncoming = inStream.readLine()) != null)
- {
- svAns += svIncoming;
- }
- inStream.close();
- }
- catch (IOException ioe)
- {
- }
- return svAns;
- }</pre>
-
- <hr>
- <a name="CONSTRUCTORS"><img src="constrct.gif" width=220 height=60 alt="Constructors"></a>
-
- <dl>
- <dt><h3>ClientIO</h3>
- <dd><code>public <strong>ClientIO</strong>();</code>
- <dd><p>Constructs a ClientIO object.</p>
- </dl>
-
- <hr>
- <a name="METHODS"><img src="methods.gif" width=220 height=60 alt="Methods"></a>
-
- <dl>
- <dt><h3>talk</h3>
- <dd><code>String <strong>talk</strong>(URL serversideEXE, String data);</code>
- <dd><p>Passes data to the <a href="serverio.htm">serverio.exe</a> serverside executable that in turn "posts"
- the data to the appropriate file. A <a href="serverio.htm">serverio.ini</a> file on the
- web server specifies the actual file where <a href="serverio.htm">serverio.exe</a> will "post".
- A String response is returned.</p>
- <p>The file is created if it does not exist, otherwise the data is appended
- to the existing file.</p>
- <dl>
- <dt><h4>Parameters:</h4>
- <dd><strong>serversideEXE</strong> - URL - The serverside executable that will post the data.
- <dd><strong>data</strong> - String - The data to write.
- </dl>
- <p></p>
-
- <dl>
- <dt><h4>Notes:</h4>
- <dd><p>If an error occurs in serverio.exe and not in the ClientIO
- class, the getLastResult() method will mistakenly return true. This is because
- ClientIO is only aware of errors that occur within the ClientIO class. If
- you want to be absolutely sure of the results, parse talk()'s return
- string using the following information.</p>
- <ul>
- <li>"Transaction complete" is returned (initiated by serverio.exe) if ClientIO and serverio.exe are successful.
- <li>"ERROR: MalformedURLException: " + (additional information) is returned from the ClientIO class if an error occurs within ClientIO.
- <li>"ERROR: IOException: " + (additional information) is returned from the ClientIO class if an error occurs within ClientIO.
- <li>"ERROR: Can't write transaction file, serverio.ini not found" is returned from serverio.exe if an error occurs within serverio.exe.
- <li>"ERROR: Can't write transaction file" is returned from serverio.exe if an error occurs within serverio.exe.
- </ul>
- <p>In most applications, parsing the return string should not be necessary once
- the serverio.exe program has been correctly installed and tested.
- ClientIO's getLastResult() method does not check the serverio.exe response data as part of it's decision
- making process because another serverside program may be used in it's place.</p>
- </dl>
- </dl>
-
- <dl>
- <dt><h3>getLastResult</h3>
- <dd><code>boolean <strong>getLastResult</strong>();</code>
- <dd><p>Returns true or false to indicate the success or failure of the
- last write attempt by talk().</p>
- </dl>
-
- <hr>
-
- <!--INCLUDESTART="JTPGNAV.TXT"-->
-
-
- <a href="formtool.htm">Previous</a>
- <a href="serverio.htm">Next</a>
- <a href="classidx.htm">Index</a><br>
-
- <!--INCLUDESTOP="JTPGNAV.TXT"-->
- <!--INCLUDESTART="JTPGIDX.TXT"-->
- <center>
- <font size="-2" face="Arial" color="FF0000">
- <strong>
- <a href="#DESCRIPTION">Description</a> |
- <a href="#EXAMPLES">Examples</a> |
- <a href="#CONSTRUCTORS">Constructors</a> |
- <a href="#METHODS">Methods</a>
- </strong>
- </font>
- </center>
- <!--INCLUDESTOP="JTPGIDX.TXT"-->
- <!--INCLUDESTART="JTCLSFTR.TXT"-->
- <center>
- <font size="-2" face="Arial" color="FF0000">
- <strong>
- <a href="../jtkit.htm", target="_top">Java Toolkit Page</a> |
- <a href="../softwr.htm", target="_top">Software</a> |
- <a href="../index.html", target="_top">Home</a><br>
- </strong>
- </font>
- </center>
-
- <p></p>
- <font size="-1">Evans Programming Java Toolkit HTML Document<br>
- Generated March 15, 1998<br>
- Revised Februrary 5, 1999<br>
- Copyright 1998-1999 Evans Programming<br>
- Send comments or corrections to <a href="mailto:davidLevans@megsinet.net">davidLevans@megsinet.net</a>
- </font>
- <!--INCLUDESTOP="JTCLSFTR.TXT"-->
-
- </font>
- </body>
- </html>
-